var Vec2 = cc.math.Vec2;
var Color4F = cc.math.Color4F;

var DrawTraceLayer = cc.Layer.extend({
	drawNode: null,
	GErrorRatio: 1.0,
	VErrorRatio: 1.0,
	times: 40,
	dtime: 0.02,
	ctor:function () {
		this._super();
		 var size = cc.winSize;
		 var helloLabel = new cc.LabelTTF("DrawTraceLayer", "Arial", 10);
        // position the label on the center of the screen
        helloLabel.x = size.width / 2 + 100;
        helloLabel.y = size.height / 2 + 100;
        // add the label as a child to this layer
        this.addChild(helloLabel, 5);
	},
	init: function() {
	 	if (!this._super()) {
	        return false;
	    }
	    drawNode = cc.DrawNode.create();
	    this.addChild(drawNode);
	    return true;
	},
	clearTrace: function() {
		this.drawNode.clear();
	},
	refreshTraceView : function(sp, ep, v, g, factor) {
	    drawNode.clear();
	    drawNode.drawSegment(sp, ep, 0.1, new Color4F(0, 1.0, 0, 1));
		var fp;
		fp.x = ep.x + v.x;
		fp.y = ep.y + v.y;

		drawNode.drawSegment(ep, new Vec2(fp.x, ep.y),0.5, new Color4F(0, 1.0, 0, 1));
		drawNode.drawSegment(ep, new Vec2(ep.x, fp.y),0.5, new Color4F(0, 1.0, 0, 1));

		var dt = 0;
		for (var i = 1; i <= times; i++) {
			dt += dtime;
			var dx = VErrorRatio*factor * v.x * dt;
			var dy = factor * v.y*dt - (-GErrorRatio*g.y*dt*dt) / 2.0;
			drawNode.drawDot(new Vec2(sp.x+dx, sp.y+dy), 2.0, new Color4F(0, 1.0, 0.5, 0.6));
		}

	}
});